From 7d5e9091554496f1ee00875bf4936336f1add071 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Sun, 27 Jul 2025 03:47:56 +0200 Subject: [PATCH] bind: update init script MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Simplify the init script, removing some unnecessary subshells and make sure that the end result is shellcheck clean. Signed-off-by: David Härdeman --- net/bind/files/named.init | 93 +++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/net/bind/files/named.init b/net/bind/files/named.init index f8405076ba..aa57e09e2d 100644 --- a/net/bind/files/named.init +++ b/net/bind/files/named.init @@ -3,66 +3,53 @@ # Licensed under the terms of the GNU General Public License version 2 # or (at your discretion) any later later version +# shellcheck disable=SC2034 USE_PROCD=1 - START=22 -config_file=/etc/bind/named.conf -config_dir=$(dirname $config_file) -pid_file=/var/run/named/named.pid - -rundir=$(dirname $pid_file) -logdir=/var/log/named/ -cachedir=/var/cache/bind -libdir=/var/lib/bind -dyndir=/tmp/bind - -conf_local_file=$dyndir/named.conf.local +config_dir=/etc/bind +run_dir=/var/run/named +log_dir=/var/log/named +cache_dir=/var/cache/bind +lib_dir=/var/lib/bind +dyn_dir=/tmp/bind -fix_perms() { - for dir in $rundir $libdir $logdir $cachedir $dyndir; do - test -e "$dir" || { - mkdir -p "$dir" - chgrp bind "$dir" - chmod g+w "$dir" - } - done -} - -no_ipv6() { - [ -z "$(ip -6 -o route show default)" ] -} +config_file=$config_dir/named.conf +config_local_file=$dyn_dir/named.conf.local reload_service() { - rndc -q reload + rndc -q reload } start_service() { - user_exists bind 57 || user_add bind 57 - group_exists bind 57 || group_add bind 57 - fix_perms - - local runnamed=$(dirname $pid_file) - # with dropped privileges, we need this created for us - [ -d $runnamed ] || { - mkdir -m 0755 $runnamed - chown bind.bind $runnamed - } - - if [ ! -s /etc/bind/rndc.key ] && [ ! -s /etc/bind/rndc.conf ]; then - rndc-confgen -a - fi - - touch $conf_local_file - - local args= - no_ipv6 && args="-4" - - procd_open_instance - procd_set_param command /usr/sbin/named -u bind -f $args -c $config_file - procd_set_param file $config_file \ - $conf_local_file \ - $config_dir/db.* - procd_set_param respawn - procd_close_instance + user_exists bind 57 || user_add bind 57 + group_exists bind 57 || group_add bind 57 + + for dir in $run_dir $log_dir $cache_dir $lib_dir $dyn_dir; do + if [ ! -e "$dir" ]; then + mkdir -p "$dir" + fi + chown bind:bind "$dir" + chmod 0775 "$dir" + done + + if [ ! -s /etc/bind/rndc.key ] && [ ! -s /etc/bind/rndc.conf ]; then + rndc-confgen -a + chown bind:bind /etc/bind/rndc.key + chmod 0640 /etc/bind/rndc.key + fi + + touch $config_local_file + + if [ -z "$(ip -6 -o route show default)" ]; then + args="-4" + else + args="" + fi + + procd_open_instance + procd_set_param command /usr/sbin/named -u bind -f $args -c $config_file + procd_set_param file $config_file $config_local_file $config_dir/db.* + procd_set_param respawn + procd_close_instance } -- 2.30.2